package dao;

import java.util.LinkedList;
import java.util.List;
import entities.Album;
import entities.Order;

public class OrderDAO {

	private static final OrderDAO instance = new OrderDAO();
	private List<Order> Orders;
	
	private OrderDAO(){
		Orders = new LinkedList<Order>();
		Order cus = null;
		
		cus = Order.newInstance("jaime", "Jaime", "Vazquez", "ja@j.com", 1L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		Orders.add(cus);
		cus = Order.newInstance("jaime1", "Jaime", "Vazquez", "ja@j.com", 2L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		Orders.add(cus);
	}
	
	public static OrderDAO getInstance() {
		return instance;
	}

	public synchronized Order findOrder(String orderID) {
		Order result = null;
		for (Order s : Orders){
			if (s.getOrderID().equals(orderID)){
				result = s;
			}
		}
		return result;
	}

	public synchronized void addOrder(Order obj) throws RecordDuplicateException{
		if (findOrder(obj.getOrderID()) != null){
			throw new RecordDuplicateException("Order with id: " + obj.getOrderID() + " is already in the db.");
		}
		else {
			Orders.add(obj);
		}
	}

}
